home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12080 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news2.ios.com!usenet
  2. From: vlad@gramercy.ios.com (Vlastimil Adamovsky)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: class for accessing indiv bits
  5. Date: Mon, 18 Mar 1996 03:52:19 GMT
  6. Organization: Internet Online Services
  7. Message-ID: <4iim8k$ime@news2.ios.com>
  8. References: <4h3396$l4f@oclc.org>
  9. NNTP-Posting-Host: ppp-54.ts-7.hck.idt.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. razin@oclc.org (Irina Razin) wrote:
  13.  
  14. >I was thinking about writing a class for simulating array
  15. >of bits, where each member of that array can serve as a
  16. >binary variable, so for example, by allocating just two
  17. >long integers I would have an array of sizeof(long)*8 
  18. >elements.
  19.  
  20. >Having such a class would be a lot of fun. Anybody have it
  21. >implemented already? I have written basic functions for 
  22. >retrieving, setting and toggling bits, but they are very
  23. >C-style. How about overloaded [],=, copy constructors etc
  24. >so it looks just like a regular data type?
  25.  
  26. It is very easy to implement.
  27. Just use a fact that byte has 8 bits, and then use bitwise logical
  28. operators like & and |.
  29. Also, you will need to use the % C language operator. That's it.
  30. Having those facts in your hands, go ahead and create a subclass of a
  31. vector of characters (bytes) and redefine and define some functions.
  32.  
  33.  
  34.  
  35. *******************************************
  36. *    Vlastimil Adamovsky                  *
  37. * Smalltalk, C++ and Envelop development  *
  38. *******************************************
  39.  
  40.